package com.fafa.File;

import org.junit.Test;

import java.io.File;
import java.io.IOException;

/**
 * 创建文件
 */
public class FileCreate {
    public static void main(String[] args) {

    }

    @Test
    public void create01() {
        String filePath = "E:\\new1.txt";
        File file = new File(filePath);
        try {
            //创建
            if (file.createNewFile())
                System.out.println("文件创建成功");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }

    @Test
    public void create02() {
        File parentFile = new File("E:\\");
        String fileName = "new2.txt";
        File file = new File(parentFile, fileName);
        try {
            if (file.createNewFile())
                System.out.println("文件创廻成功");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}


